//
//  JJHomeTableViewCell.swift
//  JJSina
//
//  Created by mac on 2017/12/6.
//  Copyright © 2017年 xinyuan. All rights reserved.
//

import UIKit
import SnapKit

class JJHomeTableViewCell: UITableViewCell {
     
    var bottomViewTopConstraint: Constraint?
    
    var statusModel: JJStatusViewModel? {
        didSet{
            originalView.statusModel = statusModel

            bottomViewTopConstraint?.deactivate()
            if statusModel?.homeModel?.retweeted_status != nil {// 有转发微博 1.赋值 2.显示
                retweetView.statusModel = statusModel
                
                bottomView.snp.makeConstraints({ (make) in
                bottomViewTopConstraint = make.top.equalTo(retweetView.snp.bottom).constraint
                })
                
                retweetView.isHidden = false
                
            } else {// 没有转发微博 1.隐藏转发微博 2.更新约束
                bottomView.snp.makeConstraints({ (make) in
                bottomViewTopConstraint = make.top.equalTo(originalView.snp.bottom).constraint
                })
                retweetView.isHidden = true
            }
        }
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - 添加视图
    private func setupUI() {
        backgroundColor = JJRandomColor()
        // 添加子控件
        contentView.addSubview(originalView)
        contentView.addSubview(bottomView)
        contentView.addSubview(retweetView)
        
        // 添加约束
        originalView.snp.makeConstraints { (make) in
            make.left.top.right.equalToSuperview()
        }
        retweetView.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview()
            make.top.equalTo(originalView.snp.bottom)
        }
        
        bottomView.snp.makeConstraints { (make) in
            bottomViewTopConstraint = make.top.equalTo(retweetView.snp.bottom).constraint
            make.left.right.equalToSuperview()
            make.height.equalTo(35)
            make.bottom.equalToSuperview()
        }
        
    }
    // MARK: - 懒加载子控件
    private lazy var originalView: JJHomeOriginalView = JJHomeOriginalView()
    private lazy var bottomView: JJHomeBottomView = JJHomeBottomView()
    private lazy var retweetView: JJHomeRetweetView = JJHomeRetweetView()
    
    
}


















